/************************************************************************************************
 * test examples of 100 interesting program in C
 * test 071.c
 * Joseph Problem
 ***********************************************************************************************/

#include <stdio.h>

/*
 * solution of book is not match the original question
 * it drops the 15th people of the sequence, but the original is 9th
 * my solution use 15, to show the same result as book's solution
 */

int main()
{
    char p[30];
    int i = 0;
    for (; i < 30; i++)
        p[i] = 'r';
    int j = 0, count = 0;
    i = 0;
    while (j < 15)
    {
        if (p[i] == 'r')
        {
            i++;
            count++;
        }
        else
            i++;
        if (i == 30)
            i = 0;
        if (count == 14 && p[i] == 'r')
        {
            p[i] = 'd';
            count = 0;
            j++;
        }
    }
    for (i = 0; i < 30; i++)
        printf("%c", p[i]);
    printf("\n");
}

